<!-- 添加专员弹窗 -->
<template>
  <a-modal
    :maskClosable="false"
    :title="title"
    centered
    :width="1000"
    v-model="visible"
    :confirmLoading="confirmLoading"
  >
    <a-form :form="form">
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="添加专员">
        <a-select
          style="width: 200px"
          placeholder="请选择"
          v-decorator="[
            'attacheId',
            { initialValue: attacheIds, rules: [{ required: true, message: '请选择专员' }] },
          ]"
          allowClear
        >
          <a-select-option
            v-for="(item, index) in perList"
            :key="index"
            :value="item.id"
            >{{ item.userName }}</a-select-option
          >
        </a-select>
      </a-form-item>
    </a-form>
    <template slot="footer">
      <a-button @click="handleSubmit">确定</a-button>
    </template>
  </a-modal>
</template>
<script>
import { attacheList, addAttacheList } from "@/api/system/system";
import Vue from "vue";
// import pick from 'lodash.pick'
import { ACCESS_TOKEN } from "@/store/mutation-types";

export default {
  components: {},
  data() {
    return {
      title: '',
      perList: [],
      visible: false,
      attacheIds: "",
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      headers: {
        token: Vue.ls.get(ACCESS_TOKEN),
      },
    };
  },
  created() {
    this.getTypeList();
  },
  methods: {
    getTypeList() {
      attacheList({ attacheType: "hyzy" }).then((res) => {
        this.perList = res.data;
      });
    },
    // moduleShow(id, attacheId) {
    //   this.id = id;
    //   this.attacheId = attacheId;
    //   this.visible = true;
    // },
    add (obj) {
      this.title= obj.title
      this.id = obj.data.id
      this.visible = true
      this.form.resetFields()
    },
    edit (obj) {
      this.title= obj.title
      this.id = obj.data.id
      this.attacheIds = Number(obj.data.currentService)
      this.visible = true
      this.form.resetFields()
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(obj.data, 'id','attacheIds'))
      })
    },
    // 发布内容
    handleSubmit(e) {
      var _this = this;
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          var params = JSON.parse(JSON.stringify(values));
          params.id = this.id;
          return addAttacheList(params)
            .then((res) => {
              _this.$message.success("新增成功", 1);
              _this.visible = false;
              _this.$emit("add");
            }).finally(() => {
              _this.confirmLoading = false;
            });
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.tree {
  max-height: 400px;
  overflow: auto;
}
/deep/ .ant-modal-footer {
  text-align: center;
}
</style>
